/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "sle_hal_test_entry.h"
#include "sle_loader_hal.h"
#include "sle_hal_errcode.h"
void InitSleHalTestLevel0(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    ret = InitSleHal();
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] InitSleHalTestLevel0 failed(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] InitSleHalTestLevel0 pass");
}

void DeinitSleHalTestLevel0(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    ret = DeinitSleHal();
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] DeinitSleHalTestLevel0 failed(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] DeinitSleHalTestLevel0 pass");
}

void GetSleHostHalOptsTestLevel0(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    SleHostHdiOpts sleHostOpts;
    ret = GetSleHostHalOpts(&sleHostOpts);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] GetSleHostHalOptsTestLevel0 failed(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleHostHalOptsTestLevel0 pass");
}

void GetSleSeekHalOptsTestLevel0(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    SleSeekHdiOpts sleSeekOpts;
    ret = GetSleSeekHalOpts(&sleSeekOpts);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] GetSleSeekHalOptsTestLevel0 failed(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleSeekHalOptsTestLevel0 pass");
}

void GetSleAnnounceHalOptsTestLevel0(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    SleAnnounceHdiOpts sleAnnounceOpts;
    ret = GetSleAnnounceHalOpts(&sleAnnounceOpts);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] GetSleAnnounceHalOptsTestLevel0 failed(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleAnnounceHalOptsTestLevel0 pass");
}

void GetSleConnectHalOptsTestLevel0(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    SleConnectHdiOpts sleConnectOpts;
    ret = GetSleConnectHalOpts(&sleConnectOpts);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] GetSleConnectHalOptsTestLevel0 failed(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleConnectHalOptsTestLevel0 pass");
}

void GetSleSsapcHalOptsTestLevel0(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    SleSsapcHdiOpts sleSsapcOpts;
    ret = GetSleSsapcHalOpts(&sleSsapcOpts);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] GetSleSsapcHalOptsTestLevel0 failed(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleSsapcHalOptsTestLevel0 pass");
}

void GetSleSsapsHalOptsTestLevel0(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    SleSsapsHdiOpts sleSsapsOpts;
    ret = GetSleSsapsHalOpts(&sleSsapsOpts);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] GetSleSsapsHalOptsTestLevel0 failed(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleSsapsHalOptsTestLevel0 pass");
}

void SleLoaderHalTestLevel0(void)
{
    SLE_UT_LOG("___SleLoaderHalTestLevel0 start");
    InitSleHalTestLevel0();
    GetSleHostHalOptsTestLevel0();
    GetSleSeekHalOptsTestLevel0();
    GetSleAnnounceHalOptsTestLevel0();
    GetSleConnectHalOptsTestLevel0();
    GetSleSsapcHalOptsTestLevel0();
    GetSleSsapsHalOptsTestLevel0();
    DeinitSleHalTestLevel0();
    SLE_UT_LOG("___SleLoaderHalTestLevel0 end");
}

void InitSleHalTestLevel1(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    ret = InitSleHal();
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] InitSleHalTestLevel1 failed1(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] InitSleHalTestLevel1 pass1");
    //测试重复调用
    ret = InitSleHal();
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] InitSleHalTestLevel1 failed2(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] InitSleHalTestLevel1 pass2");
}

void DeinitSleHalTestLevel1(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    ret = DeinitSleHal();
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] DeinitSleHalTestLevel1 failed1(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] DeinitSleHalTestLevel1 pass1");
    //测试重复调用
    ret = DeinitSleHal();
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] DeinitSleHalTestLevel1 failed2(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] DeinitSleHalTestLevel1 pass2");
}

void GetSleHostHalOptsTestLevel1(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    //测试入参为NULL
    ret = GetSleHostHalOpts(NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_ERR_INVALID_PARAM, "[SleLoaderHalTest][FAILED] GetSleHostHalOptsTestLevel1 failed1(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleHostHalOptsTestLevel1 pass1");
    //测试重复调用
    SleHostHdiOpts *sleHostOpts = (SleHostHdiOpts*) malloc(sizeof(SleHostHdiOpts));
    ret = GetSleHostHalOpts(sleHostOpts);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] GetSleHostHalOptsTestLevel1 failed3(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleHostHalOptsTestLevel1 pass2");
    ret = GetSleHostHalOpts(sleHostOpts);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] GetSleHostHalOptsTestLevel1 failed4(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleHostHalOptsTestLevel1 pass3");
    free(sleHostOpts);
}

void GetSleSeekHalOptsTestLevel1(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    //测试入参为NULL
    ret = GetSleSeekHalOpts(NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_ERR_INVALID_PARAM, "[SleLoaderHalTest][FAILED] GetSleSeekHalOptsTestLevel1 failed1(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleSeekHalOptsTestLevel1 pass1");
    //测试重复调用
    SleSeekHdiOpts *sleSeekOpts = (SleSeekHdiOpts*) malloc(sizeof(SleSeekHdiOpts));
    ret = GetSleSeekHalOpts(sleSeekOpts);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] GetSleSeekHalOptsTestLevel1 failed3(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleSeekHalOptsTestLevel1 pass2");
    ret = GetSleSeekHalOpts(sleSeekOpts);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] GetSleSeekHalOptsTestLevel1 failed4(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleSeekHalOptsTestLevel1 pass3");
    free(sleSeekOpts);
}

void GetSleAnnounceHalOptsTestLevel1(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    //测试入参为NULL
    ret = GetSleAnnounceHalOpts(NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_ERR_INVALID_PARAM, "[SleLoaderHalTest][FAILED] GetSleAnnounceHalOptsTestLevel1 failed1(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleAnnounceHalOptsTestLevel1 pass1");
    //测试重复调用
    SleAnnounceHdiOpts *sleAnnounceOpts = (SleAnnounceHdiOpts*) malloc(sizeof(SleAnnounceHdiOpts));
    ret = GetSleAnnounceHalOpts(sleAnnounceOpts);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] GetSleAnnounceHalOptsTestLevel1 failed3(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleAnnounceHalOptsTestLevel1 pass2");
    ret = GetSleAnnounceHalOpts(sleAnnounceOpts);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] GetSleAnnounceHalOptsTestLevel1 failed4(%d)", ret);
    free(sleAnnounceOpts);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleAnnounceHalOptsTestLevel1 pass3");
}

void GetSleConnectHalOptsTestLevel1(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    //测试入参为NULL
    ret = GetSleConnectHalOpts(NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_ERR_INVALID_PARAM, "[SleLoaderHalTest][FAILED] GetSleConnectHalOptsTestLevel1 failed1(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleConnectHalOptsTestLevel1 pass1");
    //测试重复调用
    SleConnectHdiOpts *sleConnectOpts = (SleConnectHdiOpts*) malloc(sizeof(SleConnectHdiOpts));
    ret = GetSleConnectHalOpts(sleConnectOpts);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] GetSleConnectHalOptsTestLevel1 failed3(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleConnectHalOptsTestLevel1 pass2");
    ret = GetSleConnectHalOpts(sleConnectOpts);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] GetSleConnectHalOptsTestLevel1 failed4(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleConnectHalOptsTestLevel1 pass3");
    free(sleConnectOpts);
}

void GetSleSsapcHalOptsTestLevel1(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    //测试入参为NULL
    ret = GetSleSsapcHalOpts(NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_ERR_INVALID_PARAM, "[SleLoaderHalTest][FAILED] GetSleSsapcHalOptsTestLevel1 failed1(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleSsapcHalOptsTestLevel1 pass1");
    //测试重复调用
    SleSsapcHdiOpts *sleSsapcOpts = (SleSsapcHdiOpts*) malloc(sizeof(SleSsapcHdiOpts));
    ret = GetSleSsapcHalOpts(sleSsapcOpts);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] GetSleSsapcHalOptsTestLevel1 failed3(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleSsapcHalOptsTestLevel1 pass2");
    ret = GetSleSsapcHalOpts(sleSsapcOpts);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] GetSleSsapcHalOptsTestLevel1 failed4(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleSsapcHalOptsTestLevel1 pass3");
    free(sleSsapcOpts);
}

void GetSleSsapsHalOptsTestLevel1(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    //测试入参为NULL
    ret = GetSleSsapsHalOpts(NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_ERR_INVALID_PARAM, "[SleLoaderHalTest][FAILED] GetSleSsapsHalOptsTestLevel1 failed1(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleSsapsHalOptsTestLevel1 pass1");
    //测试重复调用
    SleSsapsHdiOpts *sleSsapsOpts = (SleSsapsHdiOpts*) malloc(sizeof(SleSsapsHdiOpts));
    ret = GetSleSsapsHalOpts(sleSsapsOpts);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] GetSleSsapsHalOptsTestLevel1 failed3(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleSsapsHalOptsTestLevel1 pass2");
    ret = GetSleSsapsHalOpts(sleSsapsOpts);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleLoaderHalTest][FAILED] GetSleSsapsHalOptsTestLevel1 failed4(%d)", ret);
    SLE_UT_LOG("[SleLoaderHalTest][PASSED] GetSleSsapsHalOptsTestLevel1 pass3");
    free(sleSsapsOpts);
}

void SleLoaderHalTestLevel1(void)
{
    SLE_UT_LOG("___SleLoaderHalTestLevel1 start");
    InitSleHalTestLevel1();
    GetSleHostHalOptsTestLevel1();
    GetSleSeekHalOptsTestLevel1();
    GetSleAnnounceHalOptsTestLevel1();
    GetSleConnectHalOptsTestLevel1();
    GetSleSsapcHalOptsTestLevel1();
    GetSleSsapsHalOptsTestLevel1();
    DeinitSleHalTestLevel1();
    SLE_UT_LOG("___SleLoaderHalTestLevel1 end");

}

void SleLoaderHalTestEntry(void)
{
    SLE_UT_LOG("__SleLoaderHalTestEntry start");
    SleLoaderHalTestLevel0();
    SleLoaderHalTestLevel1();
    SLE_UT_LOG("__SleLoaderHalTestEntry end");
}